/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : club_view.js                                 
*  Description  : 부킹게시판 글상세 
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-05-11  이윤노    Created.  
*  2012-05-00  이윤노    Complete.  
*******************************************************************************/

jQuery(function($){
	//상단메뉴
	function clsTopMenuInfo(){
		this._HTMLDom = null;
		
		this._init();
	}
	
	clsTopMenuInfo.prototype = {
		_init: function(){
			var $layer = $("div#container nav ul.self_club_gnb");			
			this._HTMLDom = {
				"$layer":$layer
			}			
		}
		, getBtnClubHome: function(){
			var $layer = this._HTMLDom["$layer"];
			return $layer.find("li:first");
		}
		, getBtnClubField: function(){
			var $layer = this._HTMLDom["$layer"];
			return $layer.find("li:eq(1)");
		}
		, getBtnClubBoard: function(){
			var $layer = this._HTMLDom["$layer"];
			return $layer.find("li:eq(2)");
		}
		, getBtnClubPic: function(){
			var $layer = this._HTMLDom["$layer"];
			return $layer.find("li:eq(3)");
		}
		, getBtnClubAdmin: function(){
			var $layer = this._HTMLDom["$layer"];
			return $layer.find("li:eq(4)");
		}
	}
	
	
	// 컨트롤
	function clsTopControl()
	{
		this._init();
	}
	
	clsControl.prototype = {
		_init: function(){
			
			this.objClubTitle = new clsClubTitle();
			
			this._bind();
			
			// 전체게시글로 default 설정
			this.objClubTitle.setIdx((document.objUtil.getParam("q_my") == "Y") ? 1:0);
			
			// 글정보 받아오기
			if(document.objUtil.getParam("q_seq")){
				this.objClubInfo.spinStart();
				
				this.objComm.setClubRequest("키", document.objUtil.getParam("q_seq"));
				this.objComm.getClubInfo();
				
				// 댓글
				this.objClubCommentList.spinStart();
				this.objComm.setClubCommentRequest("게시판키", document.objUtil.getParam("q_seq"));
				this.objComm.getClubCommentList();
			}
		}
		, _bind: function(){
			var thisClass = this;

			// 글정보 완료
			$(this.objComm).bind("evtFinishClubInfo", function(){
				var thisData = this.getClubData();
				
				thisClass.objClubInfo.spinEnd();
				thisClass.objClubInfo.setInfo(thisData);
				
				//thisClass.objAuthButton.setAuth(document.objUtil.getCookie("member_id") == thisData["작성자"]["아이디"]);
				thisClass.objAuthButton.setAuth(true);
			// 댓글 완료
			}).bind("evtFinishClubCommentList", function(){
				var thisData = this.getClubCommentData();
				alert("댓글등록완료");
				thisClass.objClubCommentList.spinEnd();
				thisClass.objClubCommentList.setList(thisData);
			// 삭제완료
			}).bind("evtFinishClubDelete", function(){
				var ret = arguments[1];
				
				document.objGlobal.spinEnd();
				
				alert("삭제되었습니다.");
				document.location.href = "club.html?q_my="+ document.objUtil.getParam("q_my");
			});
			
			// 글쓰기
			$("div#container section#main_content div.golf_board a").has("img[alt=글쓰기]").click(function(event){
				event.preventDefault();
				
				document.location.href = "club_write.html?q_my=" + document.objUtil.getParam("q_my");
			});
			
			// 목록
			$("div#container section#main_content div.golf_board a").has("img[alt=목록]").click(function(event){
				event.preventDefault();
				
				document.location.href = "club_list.html?q_my=" + document.objUtil.getParam("q_my");
			});
			
			// 수정
			this.objAuthButton.$getBtnModify().click(function(event){
				event.preventDefault();
				
				document.location.href = "club_write.html?q_my=" + document.objUtil.getParam("q_my") + "&q_seq=" + document.objUtil.getParam("q_seq");
			});
			
			// 삭제
			this.objAuthButton.$getBtnDelete().click(function(event){
				event.preventDefault();
				
				if(!confirm("삭제하시겠습니까?")) return;
				
				document.objGlobal.spinStart("deleting...");
				thisClass.objComm.clubDelete(document.objUtil.getParam("q_seq"));
			});
			
			//
		}
	}
	
	document.objTopControl = new clsTopControl();
});